<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>7 Paradigms Template</title>
        <link href="../css/bootstrap.css" rel="stylesheet">
    </head>
    <body>
        <div class="container">
            <!-- begin imports -->
            <?php
            session_start();
            if (!isset($_SESSION['userName'])) {
                header("Location: index.php");
            }
            require_once 'paradigmShift/_paradigmShift.php';
            if (!isset($_SESSION['isManager'])) {
                $managerResults = checkIfManager($_SESSION['userName'], $_SESSION['userPassHash']);
                if ($managerResults['code'] == ErrorCode::successRead) {
                    $_SESSION['isManager'] = $managerResults['isManager'];
                } else {
                    header("Location: index.php");
                }
            }
            include_once 'checkSessionTimeout.php';
            ?>
            <!-- end imports -->
            <div class="row">
                <nav class="span12 text-center">
                    <!-- begin  header -->
                    <?php include_once 'header.php'; ?>
                    <!-- end header -->
                </nav>
            </div>
            <div class="row">
                <section class="span10 offset1">
                    <!-- begin main body -->
                    <?php
                    //determine which panel is being shown.
                    //default is "upcoming shifts"
                    $mainPanel = "upcoming";
                    if (isset($_POST['mainPanel'])) {
                        //priority is if the user wants to change panel
                        $_SESSION['mainPanel'] = $mainPanel = $_POST['mainPanel'];
                    } elseif (isset($_SESSION['mainPanel'])) {
                        //if not changing, checks to see most recent page
                        $mainPanel = $_SESSION['mainPanel'];
                    }
                    switch ($mainPanel) {
                        case "View Upcoming Per Worker":
                            include_once "main_upcomingPerWorker.php";
                            break;
                        case "Add New Account":
                            include_once "main_addAccount.php";
                            break;
                        case "Add New Shift":
                            include_once "main_addShift.php";
                            break;
                        case "Pending Requests":
                            include_once "main_pendingRequests.php";
                            break;
                        case "Shift Manager":
                            include_once "main_shiftManager.php";
                            break;
                        case "Manager Manager":
                            include_once "main_updateManagers.php";
                            break;
                        case "Employee Manager":
                            include_once "main_empManager.php";
                            break;
                        case "logout":
                            logout();
                            break;
                        case "Shift Shop":
                            include_once "main_shop.php";
                            break;
                        case "Profile":
                            include_once "main_profile.php";
                            break;
                        case "History":
                            include_once "main_history.php";
                            break;
                        default:
                            include_once "main_upcoming.php";
                            break;
                    }
                    ?>
                    <!-- end main body -->
                </section>
            </div>
            <?php if ($_SESSION['isManager']) {
                ?>
                <div class="row">
                    <footer class="span12 text-center">
                        <!-- begin footer -->
                        <?php
                        include_once 'footer.php';
                        ?>
                        <!-- end footer -->
                    </footer>
                </div>
            <?php } ?>
        </div>
        <script type="text/javascript" src="../js/jquery.js"></script>
        <script type="text/javascript" src="../js/bootstrap.js"></script>
    </body>
</html>
<?php

function logout() {
    session_destroy();
    header("Location: index.php");
}
?>